<?php

namespace App\Http\Requests\Api;

use Illuminate\Foundation\Http\FormRequest;
use App\Models\User;
use App\Services\TencentMap;

class UserAddressRequest extends ApiRequest
{
    
    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            //'shop_id' => 'required',
        ];
    }

    public function messages()
    {
       return [];
    }

    public function pure()
    {
        $data = array_except($this->all(),['token','address_id','latitude','longitude']);
        //dd($data);
        $data['user_id'] = $this->user_id;
        if(object_get($this,'longitude')) {
            $zone = TencentMap::coordiateToAddress($this->latitude.','.$this->longitude);
            $data['province'] = $zone['province'];
            $data['city'] = $zone['city'];
            $data['zone'] = $zone['district'];
            $data['lnglat'] = $this->longitude.','.$this->latitude;
              
        }
        
        return  $data;
    }
}
